<include file="Common:header" />
<TYimport plugin='datepicker' />
<TYjs file='fix_table_title'/>
<!-- <TYjs file='init'/> -->

<style>
.success{width:20%;float:left;}
.success img{width:100%}
</style>

<div class="table_content">
<a class="a_btn add_server_name" style="margin-bottom:10px;cursor:pointer;">添加月卡</a>
    <form action="" method="post" class="ajax_form">
        <table class="orders_table">
            <tr>
                <th style="min-width:100px;">月卡名</th>
                <th style="min-width:100px;">服務內容</th>
                <th style="min-width:100px;">價格</th>
                <th style="min-width:100px;">創建時間</th>
                <th style="min-width:100px;">更新時間</th>
                <th style="min-width:100px;">是否顯示</th>
                <th width="130px">操作</th>
            </tr>
            <foreach name='list' item='vo'>
                <tr>
                	<td class="txtc">{$vo.month_card_name}</td>
                	<td class="txtc">
                		<foreach name="vo['server_name_list']" item='v'>
	                		<div server-name="server_{$v.id}">
	                			<input type="hidden" value="{$v.id}">
	                			<span style="float: left;padding-left: 20%;">
	                			項目：<span style="color:#ff8800">{$v.server_name}</span>
	                			</span>
	                			<div class="cl"></div>
	                			<span style="float: right;padding-right: 20%;">
	                			次數：<span style="color:#ff8800">{$v.server_times}</span>
	                			</span>
	                		</div>
                		</foreach>
                	</td>
                	<td class="txtc">{$vo.month_card_total}元</td>
                	<td class="txtc">{$vo.create_time|date="Y-m-d H:i",###}</td>
                    <td class="txtc">{$vo.update_time|date="Y-m-d H:i",###}</td>
                    <td class="txtc">
                        <input type="button" class="js_status status_{$vo['status']?'enable':'disable'}" url="{:U(MODULE_NAME.'/Audit/change_month_status',array('id'=>$vo['id']))}"/>
                    </td>
                    <td class="txtc">
                        <a class="delete" href="{:U(MODULE_NAME.'/Audit/delete_month_list',array('id'=>$vo['id']))}" title="删除"></a>
                    </td>
                </tr>
                <tr style="height:10px;" >
                    <td class="bgcf5"colspan="8"></td>
                </tr>
            </foreach>
        </table>
    </form>
    <div class="page">{$page}</div>
</div>

<!-- 添加月卡--服务 -->
<div id="add_name" style="display:none;">
    <form action="{:U(GROUP_NAME.'/'.MODULE_NAME.'/change_delivery')}" method="post" id="upForm">
        <table class="edit_table">
        	<tr>
                <td class="tablehead">月卡名</td>
                <td><input type="text" name="month_card_name" class="w250" /></td>
            </tr>
			<tr>
				<td class="tablehead">月卡服務</td>
				<td>
					<foreach name="server" item="vo">
						<div class="check fl">
							<input type="checkbox" server_name_id="{$vo.id}" server_name="{$vo.server_name}"/>【{$vo.server_name}】&nbsp;<label class="tips">可使用</label>
							<input type='text' times_name='{$vo.id}' class='text w20 required'/>次
						</div>
					</foreach>
				</td>
			</tr>
            <tr>
                <td class="tablehead">月卡總價</td>
                <td><input type="text" name="month_card_total" />&nbsp;元</td>
            </tr>
            <tr>
                <td class="tablehead"></td>
                <td><input type="button" name="confirm_server_name" value="添加" style="padding:6px 20px;"/></td>
            </tr>
        </table>
    </form>
</div>
<script type="text/javascript">
    $(function() {
        // 添加月卡
    	$('.add_server_name').click(function(){
    		art.dialog({
    			title:'添加月卡',
     			content: document.getElementById('add_name'),
    		});
    	});
    	$('input[name=confirm_server_name]').click(function(){
    		var flag = true; //存取数据
    		var saveData = {}; //存取数据
    		var server_name_id = ''; //服务内容
    		if ($('input[name=month_card_name]').val() =='') {
				callBackTips(0,'月卡名不能爲空!');
				return false;
			}
			if ($("input[type='checkbox']:checked").length < 1) {
				callBackTips(0,'服务内容至少勾選一項!');
				return false;
			}
			$('input[type=checkbox]').each(function(){
				if($(this).prop('checked')){
					if ($(this).attr('server_name_id')=='' || $(this).attr('server_name')=='' || $(this).next().next().val()=='') {
						callBackTips(0,'勾選服务次數不能爲空!');
						flag = false;
					}
					server_name_id += $(this).attr('server_name_id')+'|'+ $(this).attr('server_name')+'|'+ $(this).next().next().val() + ',' ;
				}
			});
			//判断每一项服务次數是否为空
			if (!flag) return flag;

			if ($('input[name=month_card_total]').val() =='') {
				callBackTips(0,'月卡總價不能爲空!');
				return false;
			}
			saveData.month_card_name = $('input[name=month_card_name]').val();
			saveData.month_card_total = $('input[name=month_card_total]').val();
			saveData.server_name_list = server_name_id;
    		$.ajax({
                url: "{:U(MODULE_NAME.'/'.CONTROLLER_NAME.'/add_month_card')}" ,
                type: 'POST',
    	        data : saveData,
    	        async: false,
    			dataType: 'json',
                success: function (returndata) {
               		if(returndata.status){
               		    callBackTips(returndata.status,returndata.info,returndata.url);
            		}else{
            			callBackTips(0,returndata.info);
            		}
                },
           });
    	});
    });
</script>
<include file="Common:footer" />
